package fr.fermeManager.application.utils;

import org.springframework.context.ApplicationContext;

import fr.fermeManager.application.controllers.BaseController;
import fr.fermeManager.application.controllers.MenuController;
import fr.fermeManager.application.frames.MainFrame;
import fr.fermeManager.application.views.BasePanel;

/**
 * This class provides application-wide access to the Spring ApplicationContext.
 * The ApplicationContext is injected by the class "ApplicationContextProvider".
 *
 * @author Siegfried Bolz
 */
public class AppContext {

    private static ApplicationContext ctx;
    
    private static SessionManager session = new SessionManager();
    
    private static MenuController menuController;
    
    private static BaseController currentController;
    
    /**
     * Injected from the class "ApplicationContextProvider" which is automatically
     * loaded during Spring-Initialization.
     */
    public static void setApplicationContext(ApplicationContext applicationContext) {
        ctx = applicationContext;
    }

    /**
     * Get access to the Spring ApplicationContext from everywhere in your Application.
     *
     * @return
     */
    public static ApplicationContext getApplicationContext() {
        return ctx;
    }

	/**
	 * @return the session
	 */
	public static SessionManager getSession() {
		return session;
	}
	
	public static void setBasePanel(BasePanel basePanelParam,boolean pack){
		MainFrame mainFrame = (MainFrame) ctx.getBean(Constantes.MAIN_FRAME);
		mainFrame.setBasePanel(basePanelParam,pack);
		
	}
	
	public static BasePanel getBasePanel(){
		MainFrame mainFrame = (MainFrame) ctx.getBean(Constantes.MAIN_FRAME);
		return mainFrame.getBasePanel();
	}

	/**
	 * @return the menuController
	 */
	public static MenuController getMenuController() {
		return menuController;
	}

	/**
	 * @param menuController the menuController to set
	 */
	public static void setMenuController(MenuController menuController) {
		AppContext.menuController = menuController;
	}

	/**
	 * @return the currentController
	 */
	public static BaseController getCurrentController() {
		return currentController;
	}

	/**
	 * @param currentController the currentController to set
	 */
	public static void setCurrentController(BaseController currentController) {
		AppContext.currentController = currentController;
	}
}